#include <bits/stdc++.h>
using namespace std;
#define N 200005
int T,a[N],n,co[N];
long long cmax=0;
void dfs(int i)
{
    if(i>n)
    {
        long long cnt=0;
        int recentred=0,recentblue=0;
        for(int j=1;j<=n;j++)
        {
            if(co[j]==1)
            {
                if(recentred!=0&&a[recentred]==a[j]) cnt+=a[j];
            }
            else
                if(recentblue!=0&&a[recentblue]==a[j]) cnt+=a[j];

            if(co[j]==1) recentred=j;
            else recentblue=j;
        }
        cmax=max(cnt,cmax);
        return;
    }
    co[i]=1;
    dfs(i+1);
    co[i]=2;
    dfs(i+1);
    co[i]=0;
    return;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--)
    {
        memset(a,0,sizeof(a));
        memset(co,0,sizeof(co));
        cmax=0;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        dfs(1);
        cout<<cmax<<'\n';
    }
    return 0;
}
